<template>
	<div class="covert">
		<div v-for="(item, index) in tabbar" :key="index" @click="showPopup(item.type)">
			<div class="icon" :class="item.class">
				<!-- <img :src="item.img" alt=""> -->
			</div>
			<div class="text">{{ item.name }}</div>
		</div>
	</div>
	<!-- <div class="block"></div> -->
	<u-modal :show="modal.show" confirmColor='#b06678' cancelColor='#333' showCancelButton @confirm="sendMessage" @cancel="modal.show = false">
		<view class="slot-content">
		<!-- 	<u-image :show-loading="true" :src="modal.img" width="568rpx" height="288rpx"></u-image> -->
			<div class="title">{{ modal.title }}</div>
			<div class="title1">{{ modal.content }}</div>
		</view>
	</u-modal>
</template>

<script setup>
	import {
		ref,defineProps
	} from "vue";
	import covertContactMessage from "@/wfc/messages/covertContactMessage";
	import store from "@/store";
	import QuoteInfo from "@/wfc/model/quoteInfo";
	import wfc from "@/wfc/client/wfc";
	import Draft from "../util/draft";
	import {
		userStore
	} from "@/pinia";
	import {
		getJobContact,
		getInteractionDic,
		setImInteraction,
		getResume
	} from "@/common/im";
	import {
		useRouter
	} from "uni-mini-router";
	
import {
	req
} from '@/common/vmeitime-http/'
import api from '@/common/api.js'
const props = defineProps({
	jobid:String,dfid:String
});
	const userStoreInfo = userStore();
	const router = useRouter()
	const userFlag = userStoreInfo.userFlag;

	const modal = ref({
		show: false,
		img: "",
		title: "",
		content: "",
	});

	const dic = [{
			name: "打电话",
			type: "phone",
			userFlag: 0,
			class: "phone",
			title: "确定与对方交换电话吗？",
			content: "确定后，电话请求将发送至对方，对方同意后会将会彼此看到手机号",
		},
		{
			name: "换微信",
			type: "wx",
			userFlag: 0,
			class: "wx",
			title: "确定与对方交换微信吗？",
			content: "确定后，微信请求将发送至对方，对方同意后会将会彼此看到微信",
		},
		{
			name: "发简历",
			type: "resume",
			userFlag: 0,
			class: "jianli",
			title: "确定向对方发送简历吗？",
			content: "确定后，简历将发送至对方，对方同意后会将会彼此看到附件简历",
		},
		{
			name: "求简历",
			type: "resume",
			userFlag: 2,
			class: "jianli",
			title: "确定向牛人请求简历吗？",
			content: "确定后，简历将发送至对方，对方同意后会将会彼此看到附件简历",
		},
		{
			name: "打电话",
			type: "phone",
			userFlag: 2,
			class: "phone",
			title: "确定与对方交换电话吗？",
			content: "确定后，电话请求将发送至对方，对方同意后会将会彼此看到手机号",
		},
		{
			name: "换微信",
			type: "wx",
			userFlag: 2,
			class: "wx",
			title: "确定与对方交换微信吗？",
			content: "确定后，微信请求将发送至对方，对方同意后会将会彼此看到微信",
		},
		{
			name: "面试",
			type: "interview",
			userFlag: 2,
			class: "mianshi",
			title: "确定向对方发送面试邀请吗？",
			content: "确定后，面试邀请将发送给对方",
		},{
			name: "求简历",
			type: "resume",
			userFlag: 1,
			class: "jianli",
			title: "确定向牛人请求简历吗？",
			content: "确定后，简历将发送至对方，对方同意后会将会彼此看到附件简历",
		},
		{
			name: "打电话",
			type: "phone",
			userFlag:1,
			class: "phone",
			title: "确定与对方交换电话吗？",
			content: "确定后，电话请求将发送至对方，对方同意后会将会彼此看到手机号",
		},
		{
			name: "换微信",
			type: "wx",
			userFlag: 1,
			class: "wx",
			title: "确定与对方交换微信吗？",
			content: "确定后，微信请求将发送至对方，对方同意后会将会彼此看到微信",
		},
		{
			name: "面试",
			type: "interview",
			userFlag: 1,
			class: "mianshi",
			title: "确定向对方发送面试邀请吗？",
			content: "确定后，面试邀请将发送给对方",
		},
	];

	const tabbar = dic.filter((f) => userFlag == f.userFlag);

	const showPopup = (type) => {
		const clickItem = tabbar.find((d) => d.type === type);
		modal.value = {
			show: true,
			...clickItem,
		};
	};
const getJobContactnew = ()=>{
	if (userFlag == 0) { // 应聘者
		return req('POST', api.jobContact, {
			jobId:props.jobid,
		})
	}else{
		return req('POST', api.jobContact2, {
			jobId:props.jobid,
			hunterId:props.dfid,
		})
	}
}
	const sendMessage = async () => {
		const jobContactRes = await getJobContactnew();
		console.log('jobContactRes', jobContactRes);
		const jobContact = jobContactRes.result;
		console.log('jobContact', jobContact);
		const field = getInteractionDic(modal.value.type);
		console.log('field', field);
		if (modal.value.type != 'interview' && (jobContact[field] != 0&&jobContact[field] != null)) {
			// 被拒绝或已经申请过了
			uni.showToast({
				title: "被拒绝或已经申请过了",
				icon: "none",
			});
			return;
		}
		let phoneMessageContent;
		// 简历
		console.log('开始获取简历');
		let resume =null
		if (userFlag == 0) { // 应聘者
			 resume = await getResume();
		}else{
			 resume = await req('GET', api.meiyeRecruitHrInfo3QueryById, {
				id: userStoreInfo.userInfo.id
			})
		}
		
		console.log('resume 获取简历 :>> ', resume);
		if (modal.value.type) console.log("modal.value.type", modal.value.type);
		if (modal.value.type == "phone") {
			phoneMessageContent = new covertContactMessage("phone",JSON.stringify({ phone:resume.result.phone,realName:resume.result.realName}));
			setImInteraction(field, 1,props.jobid,props.dfid);
		} else if (modal.value.type == "wx") {
			phoneMessageContent = new covertContactMessage("wx", JSON.stringify({ wechatNumber:resume.result.wechatNumber,realName:resume.result.realName}));
			setImInteraction(field, 1,props.jobid,props.dfid);
		} else if (modal.value.type == "resume") {
			
			phoneMessageContent = new covertContactMessage(
				"resume",
				JSON.stringify(resume.result)
			);
			setImInteraction(field, 1,props.jobid,props.dfid);
		} else if (modal.value.type == "interview") {
			userStoreInfo.updatadfid(props.dfid)
			uni.setStorageSync("interviewTime", null);
			uni.setStorageSync("interviewText", null);
			// 面试
			router.push({
				name: "inviteInterview"
			})
		}
		// let phoneMessageContent = new TextMessageContent('15631143241');
		let quotedMessage = store.state.conversation.quotedMessage;
		if (quotedMessage) {
			let quoteInfo = QuoteInfo.initWithMessage(quotedMessage);
			phoneMessageContent.setQuoteInfo(quoteInfo);
			store.quoteMessage(null);
		}
		let currentConversation =
			store.state.conversation.currentConversationInfo.conversation;
		console.log({
			currentConversation,
		});
		wfc.sendConversationMessage(currentConversation, phoneMessageContent);
		Draft.setConversationDraft(currentConversation, "", null);
		modal.value.show = false;
		store.loadConversationHistoryMessages(() => {}, () => {});
	};
</script>

<style lang="scss" scoped>
	// .block {
	//   // margin-top: 88rpx;
	//   height: 176rpx;

	// }

	.covert {
		padding: 0 35px;
		position: absolute;
		// top: 88rpx;
		top: 0%;
		left: 0%;

		width: 100%;
		height: 88rpx;

		box-sizing: border-box;

		display: flex;
		justify-content: space-between;
		align-items: center;

		z-index: 9999;

		$color: #666e7a;

		background: #fff;

		.icon {
			margin: 0 auto;
			// border: 1rpx solid $color;

			&.phone {
				width: 24rpx;
				height: 35rpx;
				background-image: url(@/static/images/im/phone.png);
				background-size: 100% 100%;
			}

			&.wx {
				width: 33rpx;
				height: 35rpx;
				background-image: url(@/static/images/im/wx.png);
				background-size: 100% 100%;
			}

			&.mianshi {
				width: 28rpx;
				height: 35rpx;
				background-image: url(@/static/images/im/mianshi.png);
				background-size: 100% 100%;
			}

			&.jianli {
				width: 35rpx;
				height: 35rpx;
				background-image: url(@/static/images/im/jianli.png);
				background-size: 100% 100%;
			}


			img {
				width: 100%;
				height: 100%;
			}
		}

		.text {
			font-family: PingFangSC-Regular;
			font-weight: 400;
			font-size: 12px;
			color: $color;
			letter-spacing: 0.2px;
			text-align: justify;
		}
	}

.title{
	font-size: 20px;
	font-weight: bold;
	margin-bottom: 10px;
}
</style>